package common

import (
	"bytes"
	"os/exec"
)

func NewCommand() *Command {
	var stdout, stderr bytes.Buffer

	return &Command{
		stdout: stdout,
		stderr: stderr,
	}
}

type Command struct {
	stdout bytes.Buffer
	stderr bytes.Buffer
}

func (r *Command) Run(command string, options ...string) (error, bytes.Buffer, bytes.Buffer) {
	result := exec.Command(command, options...)

	var stdout, stderr bytes.Buffer
	result.Stdout = &stdout
	result.Stderr = &stderr

	return result.Run(), stdout, stderr
}
func (r *Command) Exec(command string, options ...string) error {
	result := exec.Command(command, options...)

	result.Stdout = &r.stdout
	result.Stderr = &r.stderr

	return result.Run()
}

func (r *Command) CudaInfo() {
	err := r.Exec("nvidia-smi") // , "-f", "json"
	if err != nil {
		panic(err)
	}
}
